import 'package:app_test/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

// void main() {
//   // IntegrationTestWidgetsFlutterBinding.ensureInitialized();
//   testWidgets('Counter increments smoke test', (WidgetTester tester) async {
//     await tester.pumpWidget(const MyApp());
//     final ac = find.byKey(ValueKey('a1'));
//     final icon = find.byIcon(Icons.add);
//     for (var i = 1; i <= 10; i++) {
//       await tester.tap(icon);
//       await tester.pumpAndSettle();
//       expect(tester.getSize(ac).height, 200 + 100 * i);
//     }
//     // expect(tester.getSize(ac).height, 200);
//
//     // await Future.delayed(Duration(seconds: 5));
//
//     final sv = find.byType(SingleChildScrollView);
//     await tester.drag(sv, const Offset(0, -1200));
//     await tester.pumpAndSettle();
//     await Future.delayed(Duration(seconds: 5));
//
//     final tf = find.byKey(ValueKey('t1'));
//     await tester.enterText(tf, "aaaaa");
//     await tester.pumpAndSettle();
//
//     expect(tester.getSize(ac).height, 1200);
//   });
// }

void main() {
  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    await tester.pumpWidget(MyApp());

    // 启动
    soutInfo(step: '1', des: '应用程序启动');
    await tester.pumpAndSettle();
    await delayTime();

    // 打开抽屉
    final drawer = find.byKey(ValueKey('drawerButton'));
    await tester.tap(drawer);
    soutInfo(step: '2', des: '单击菜单按钮打开抽屉菜单');
    await tester.pumpAndSettle();
    await delayTime();

    // 点击技能类型
    final listSecond = find.byKey(ValueKey('listSecond'));
    await tester.tap(listSecond);
    soutInfo(step: '3', des: '单击技能类型“信息和通信技术”');
    await tester.pumpAndSettle();
    await delayTime();

    // 点击显示新闻列表
    final news = find.byKey(ValueKey('news'));
    await tester.tap(news);
    soutInfo(step: '4', des: '点击显示新闻列表');
    await tester.pumpAndSettle();
    await delayTime();

    // 滚动到伦敦
    final listView = find.byKey(ValueKey('LisyView'));
    await tester.drag(listView, const Offset(0, -1200));
    soutInfo(step: '5', des: '滚动到伦敦');
    await tester.pumpAndSettle();
    await delayTime();

    // 打开抽屉
    await tester.tap(drawer);
    soutInfo(step: '6', des: '打开抽屉');
    await tester.pumpAndSettle();
    await delayTime();

    // 点击搜索
    final search = find.byKey(ValueKey('search'));
    await tester.tap(search);
    soutInfo(step: '7', des: '点击搜索');
    await tester.pumpAndSettle();
    await delayTime();

    final titleField = find.byKey(ValueKey('titleField'));
    final nameField = find.byKey(ValueKey('nameField'));
    final startField = find.byKey(ValueKey('startField'));
    final endField = find.byKey(ValueKey('endField'));

    // 输入标题
    await tester.enterText(titleField, 'web');
    soutInfo(step: '8', des: '输入标题');
    await tester.pumpAndSettle();
    await delayTime();

    // 输入技能
    await tester.enterText(nameField, 'Mobile');
    soutInfo(step: '9', des: '输入技能');
    await tester.pumpAndSettle();
    await delayTime();

    // 输入时间
    await tester.enterText(startField, '03/21/2022');
    await tester.enterText(endField, '09/30/2022');
    soutInfo(step: '10', des: '输入时间');
    await tester.pumpAndSettle();
    await delayTime();

    // 搜索
    final searButton = find.byKey(ValueKey('searchButton'));
    await tester.tap(searButton);
    soutInfo(step: '11', des: '搜索');
    await tester.pumpAndSettle();
    await delayTime();

    // 滚动到第十个新闻
    await tester.drag(listView, const Offset(0, 100));
    soutInfo(step: '12', des: '滚动到10');
    await tester.pumpAndSettle();
    await delayTime();

    //点击第十个新闻
    final new10 = find.byKey(ValueKey('new10'));
    await tester.tap(new10);
    soutInfo(step: '13', des: '点击第十个新闻');
    await tester.pumpAndSettle();
    await delayTime();

    //点击"+"按钮
    final add = find.byKey(ValueKey('add'));
    await tester.tap(add);
    soutInfo(step: '14', des: '点击"+"按钮');
    await tester.pumpAndSettle();
    await delayTime();

    //单击关闭图标按钮
    final clearButton = find.byKey(ValueKey('clearButton'));
    await tester.tap(clearButton);
    soutInfo(step: '15', des: '单击关闭图标按钮');
    await tester.pumpAndSettle();
    await delayTime();
  });
}

Future delayTime() async {
  await Future.delayed(Duration(seconds: 2));
}

void soutInfo({
  required String step,
  required String des,
}) {
  print('Step No:$step,$des');
}
